home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-15 | 4.2 KB | 146 lines | [TEXT/MPS ] |
- //
- // Atom0.c
- //
- // Demonstration of a format0 action atom.
- //
- // A dialog is provided that allows the user to select
- // the return value for the action atom.
- //
- // Scriptwriters should be aware that the return values
- // and the actions that they invoke from the installer
- // are different depending on which format of action atom
- // is being used.
- //
- // NOTE: Displaying dialogs from within an action atoms
- // can enhance or detract from the user experience, and
- // should be done with consideration to the overall flow
- // of installation. A good rule of thumb is to never display
- // dialogs from an action atom unless absolutely necessary.
- // This example is very useful in demonstrating behavior of
- // the installer in regards to return values from an action
- // atom, but is a terrible example of user interface design.
- //
- // mark young • 07/10/94
- //
- // Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
- //
-
- #include <Traps.h>
- #include <Types.h>
- #include <dialogs.h>
-
- // this line replaces #include "ActionAtomIntf.h" used in Installer 3.x action atoms
- #include "ActionAtomHeader.h"
-
- // this is needed for highliting the default button in dialog
- pascal OSErr SetDialogDefaultItem ( DialogPtr theDialog,
- short newItem ) = {0x303C,0x0304,0xAA68};
-
- // NOTE: The name of this function 'ActionAtomFormat0' should
- // match that specified in the -m option for the line in the
- // makefile that compiles this action atom.
- pascal Boolean ActionAtomFormat0( AAPBRecPtr atomRecPtr )
- {
-
- DialogPtr theDialog; // for dialog
- OSErr theOSError = 0; // for errors
-
- short theItemHit; // gets user response from ModalDialog()
- short iType; // gets control type from GetDItem()
- Handle iHandle; // gets control handle from GetDItem()
- Rect iRect; // gets control rect from GetDItem()
-
- short currRadioButton = 2; // current selected radio button
- short gettingUserResponse = true; // flag for while loop
-
- short theStatus = 0; // value to return from function
-
- // this gets rid of those annoying messages during MPW compiles
- // informing us that certain items were not used
- #pragma unused( atomRecPtr )
-
- // retrieve DLOG/DITL 128 from compiled resource script
- theDialog = GetNewDialog( 128, nil, (WindowPtr) -1 );
-
- // activate OK button when enter or return key is pressed
- theOSError = SetDialogDefaultItem( theDialog, 1 );
-
- // set up the radio button group ( controls 2 - 3 )
- GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // select the new dialog
- SelectWindow( (WindowPtr) theDialog );
-
- // show the new dialog
- ShowWindow( (WindowPtr) theDialog );
-
- // keep getting response from user until
- // the OK is activated in the new dialog
- gettingUserResponse = true;
- while ( gettingUserResponse )
- {
- // get user selection from the new dialog
- ModalDialog( nil, &theItemHit );
- switch ( theItemHit )
- {
- // first control is the OK key
- case( 1 ) :
- // exit loop
- gettingUserResponse = false;
- break;
-
- // all other controls in dialog are radio buttons
- default :
- // continue with loop
- gettingUserResponse = true;
-
- // if the radio button selection changed
- if ( currRadioButton != theItemHit )
- {
- // turn previous radio button off
- GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // turn current radio button on
- GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- // save current radio button choice
- currRadioButton = theItemHit;
- }
- break;
- }// switch
-
- }// while
-
- // get rid of the new dialog
- DisposDialog( theDialog );
-
- // select a value to return from this function according to
- // which radio button was selected in the dialog
- switch ( currRadioButton )
- {
- // return false
- case( 2 ) : theStatus = false; // user selected to return 0
- break;
-
- // return true
- case( 3 ) : theStatus = true; // user selected to return 1
- break;
-
- }
-
- // return value selected by user in dialog
- return( theStatus );
-
- }
-
-
-
-
-
-